package kit.edu.lego.gruppe3.levels.bridge;

import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSolver;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import kit.edu.lego.gruppe3.levels.door.DoorSolver;
import kit.edu.lego.gruppe3.levels.labyrinth.LabyrinthSolver;
import kit.edu.lego.gruppe3.levels.rollbridge.RollBridgeSolver;
import kit.edu.lego.gruppe3.levels.sumpf.SumpfSolver;
import kit.edu.lego.gruppe3.levels.treeArea.TreeAreaSolver;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;

/**
 * Starts the behaviors for the robot when he is on the bridge
 * @author Lac
 *
 */
public class BridgeSolver implements LevelSolver
{
	
	
	public BridgeSolver()
	{

	}


	@Override
	public void start()
	{
		finishPreviousLevels();
		LevelSelector.getInstance().setCurrentLevel(Level.bridge);
		System.out.println("Bridge level");
		Behavior moveOnRight = new MoveOnRightSide();
		Behavior moveFromEdge = new BridgeEdgeEvader();
		Behavior moveFromWall = new RightWallEvader();
		Behavior bridgeEnd = new EndOfBridge();
		
		Behavior[] bridgeBehaviors = {moveOnRight, moveFromEdge, moveFromWall, bridgeEnd};
		
		Arbitrator arby = new Arbitrator(bridgeBehaviors);
	
		arby.start();
		
	
	}
	
	private void finishPreviousLevels()
	{
		LabyrinthSolver.setLevelCleared(true);
		SumpfSolver.setLevelCleared(true);
		RollBridgeSolver.setLevelCleared(true);
		DoorSolver.setLevelCleared(true);
		TreeAreaSolver.setLevelCleared(true);
	}
	
	@Override
	public String toString()
	{
		return "Bridge solver";
	}
	
	private static boolean levelCleared = false;
	
	public static boolean isLevelCleared()
	{
		return levelCleared;
	}
	
	public static void setLevelCleared(boolean cleared)
	{
		levelCleared = cleared;
	}

}
